package com.ouman.luoliluoli;

import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.ouman.luoliluoli.models.UserInfo;
import com.ouman.luoliluoli.utils.ThemeChanger;

public class UserActivity extends AppCompatActivity implements UserFragment.OnFragmentInteractionListener,
        UserInfoFragment.OnFragmentInteractionListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ThemeChanger.applyTheme(this, null);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_user_activity);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null){
            getSupportActionBar().setTitle("个人主页");
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(UserActivity.this);
        Boolean isLogin = preferences.getBoolean("isLogin", false);
        if (!isLogin){
            // 没有登陆
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_user,
                    new UserFragment()).commit();

        }else{
            // 直接跳转到main
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_user,
                    new UserInfoFragment()).commit();
        }


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if (id == android.R.id.home){
            UserActivity.this.finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void onFragmentInteraction(Uri uri){

    }
}
